import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home'),
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login'),
    meta: {
      isHideFooter: true,
    },
  },
  {
    path: '/register',
    name: 'Register',
    component: () => import('@/views/Register'),
    meta: {
      isHideFooter: true,
    },
  },
  // 搜索页面的路由规则
  {
    path: '/search/:keyword?',
    name: 'Search',
    component: () => import('../views/Search'),
  },
  {
    path: '/detail:id?',
    name: 'Detail',
    component: () => import('../views/Detail'),
  },
  {
    path: '/AddCartSuccess',
    name: 'AddCartSuccess',
    component: () => import('../views/AddCartSuccess'),
  },
  {
    path: '/Shopcart',
    name: 'ShopCart',
    component: () => import('@/views/ShopCart'),
    meta: {
      isHideFooter: true,
      isShopCart: 1,
    },
  },
  {
    path: '/PaySuccess',
    name: 'PaySuccess',
    component: () => import('@/views/PaySuccess'),
    meta: {
      isHideFooter: true,
      isShopCart: 3,
    },
  },
  {
    path: '/pay',
    name: 'Pay',
    component: () => import('@/views/pay'),
    meta: {
      isHideFooter: true,
      isShopCart: 2,
    },
  },
]

// 滚动行为
const router = new VueRouter({
  mode: 'history',
  routes,
  //滚动行为 当你路由跳转时生效
  scrollBehavior() {
    return { x: 0, y: 0 }
  },
})

// router.beforeEach((to, from, next) => {
//   console.log('to', to, 'from', from, next)
//   if (to.name === 'ShopCart' && from.name === 'Pay') {
//     // next('/ShopCart')
//   }
//   next()
// })

export default router
